package com.six.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.pojo.Supplier;
import com.six.pojo.dto.SupplierDto;
import com.six.pojo.vo.SupplierVo;
import com.six.result.Result;
import com.six.result.ResultUtils;
import com.six.service.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/supplier")
@Api(tags = "供应商相关接口")
@Slf4j
@CrossOrigin
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    @ApiOperation(value = "供应商列表",notes = "供应商列表",httpMethod = "POST")
    @PostMapping("/list")
    public Result list(@RequestBody SupplierVo supplierVo){
        //模糊分页查询
        Page<Supplier> page =new Page<>(supplierVo.getPage(),supplierVo.getLimit());
        Page<SupplierDto> pageByQueryVo = supplierService.findSupplierPageByQueryVo(page,supplierVo);
        return ResultUtils.buildSuccess(pageByQueryVo.getTotal(),pageByQueryVo.getRecords());
    }

    @ApiOperation(value = "id查找",notes = "id查找",httpMethod = "GET")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Long id){
        SupplierDto supplierDto = supplierService.findSupplierById(id);
        return ResultUtils.buildSuccess(supplierDto);
    }

    /*@ApiOperation(value = "添加",notes = "添加",httpMethod = "POST")
    @GetMapping("/add")
    public Result add(@RequestBody Supplier supplier){
    }*/

}
